// components/navBar/navBar.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        tabs: {
            type: Array,
            value: ['全部', '核酸检测', '入职检测', '青年体检', "驾照体检", "健康护理", "美容修复"]
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        tab: 0
    },
    lifetimes: {
        attached() {
            let {
                tab
            } = this.data
            this.triggerEvent("type", this.properties.tabs[tab])
        }
    },

    /**
     * 组件的方法列表
     */
    methods: {
        choice: function (e) {
            let {
                tab
            } = e.currentTarget.dataset
            this.setData({
                tab
            })
            this.scrollTo(tab)
            this.triggerEvent("type", this.properties.tabs[tab])
        },
        scrollTo(step) {
            wx.getSystemInfo({
                success: (result) => {
                    let temp = Math.ceil((result.windowWidth) / 5)
                    let scrollLeft = 0
                    if (step > 3) {
                        scrollLeft = temp * step
                    }
                    this.setData({
                        scrollLeft
                    })
                },
            })
        }
    }
})